﻿using GeoSketch2.Core;

namespace GeoSketch2.Archaeo
{
    /// <summary>
    /// A GeoDisplay box, that will take into account the digging height, for digging purpose,
    /// will only display the object at the current digging height
    /// </summary>
    public partial class DisplayBox : BaseGeoDisplayBox
    {
        #region Fields

        #endregion

        #region Constructor
        /// <summary>
        /// A GeoDisplay box, that will take into account the digging height, for digging purpose,
        /// will only display the object at the current digging height
        /// </summary>
        public DisplayBox()
        {
            InitializeComponent();
            //Viewport = new Viewport(this);
        } 
        #endregion

        #region Methods
        /// <summary>
        /// Redraws all the objects according to the current digging height, layer visibility and order
        /// </summary>
        protected override void Redraw()
        {
            Viewport vp = Viewport;
            
            vp.ClearScene();
            foreach(Layer layer in vp.CurrentExcavationArea.AvailableLayers)
            {
                foreach (BaseArchaeoDrawableObject obj in vp.GeoObjects)
                {
                    if (obj.Layer == layer)
                    {
                        if (Viewport.DiggingMode)
                        {
                            if (obj.ExcavationArea.DiggingHeight.Id == vp.CurrentDiggingHeight.Id)
                            {
                                if (obj.Layer.Visible)
                                {
                                    obj.Draw(vp);
                                }
                            }
                        }
                        else
                        {
                            if (obj.Layer.Visible)
                            {
                                obj.Draw(vp);
                            }
                        }
                    }
                }
            }
            vp.DisplayScene();
            //Vars.temp++;
            //System.Console.WriteLine(Vars.temp);
        }

        /// <summary>
        /// The painting event
        /// </summary>
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs pe)
        {
            base.OnPaint(pe);
            Viewport.CurrentExcavationArea.Draw(Viewport);
        }
        #endregion

        #region Properties
        /// <summary>
        /// Gets the viewport of the displaybox
        /// </summary>
        public new Viewport Viewport
        {
            get
            {
                return ((Viewport)base.Viewport);
            }
            set
            {
                base.Viewport = value;
            }
        } 
        #endregion
    }
}
